package com.zgg.config;

import com.zgg.filter.CorsFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.DispatcherType;

//import com.incar.filter.JwtAuthorizeFilter;

/**
 * Filter配置
 *
 * @author chencq
 * @email chenchaoqun@incar100.com
 */
@Configuration
public class FilterConfig {

    @Bean
    public FilterRegistrationBean corsFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setDispatcherTypes(DispatcherType.REQUEST);
        registration.setFilter(new CorsFilter());
        registration.setAsyncSupported(true);
        // 该值缺省为false，表示生命周期由SpringApplicationContext管理，设置为true则表示由ServletContainer管理
        registration.addInitParameter("targetFilterLifecycle", "true");
        registration.setName("corsFilter");
        registration.addUrlPatterns("/*");
        //从小到大的顺序来依次过滤
        registration.setOrder(Integer.MAX_VALUE - 10);
        return registration;
    }
}
